package com.netty.server;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;

import com.netty.server.handler.ServerHandler;

public class ServerChannelInitializer extends ChannelInitializer<Channel> {

	@Override
	protected void initChannel(Channel channel) throws Exception {
		ObjectDecoder obj = new ObjectDecoder(1024 * 1024,
				ClassResolvers.weakCachingConcurrentResolver(this.getClass()
						.getClassLoader()));
		channel.pipeline().addLast(obj);
		// 添加对象编码器 在服务器对外发送消息的时候自动将实现序列化的POJO对象编码
		channel.pipeline().addLast(new ObjectEncoder());
		channel.pipeline().addLast(new ServerHandler());
	}

}
